﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("请根据数字选择");
                Console.WriteLine("1.foreach_统计字符 2.数组_统计和和平均值 3.数组排序的方法 4.找数组元素 5.打印九九乘法表 6.打印空心正方形");
                Console.WriteLine("7.打印菱形 8.打印实心正方形 9.数组练习_下标偶数 10.数组排序 11.打印杨辉三角形");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:
                        Text1();
                        break;
                    case 2:
                        Text2();
                        break;
                    case 3:
                        Text3();
                        break;
                    case 4:
                        Text4();
                        break;
                    case 5:
                        Text5();
                        break;
                    case 6:
                        Text6();
                        break;
                    case 7:
                        Text7();
                        break;
                    case 8:
                        Text8();
                        break;
                    case 9:
                        Text9();
                        break;
                    case 10:
                        Text10();
                        break;
                    case 11:
                        Text11();
                        break;
                    default:
                        Console.WriteLine("您输入有误，请重新输入");
                        break;
                }
            }
        }
        static void Text1()
        {
            Console.WriteLine("请输入一个字符串");
            string arr = Console.ReadLine();
            int a = 0;
            int b = 0;
            int c = 0;
            foreach (char arr1 in arr)
            {
                if (char.IsLetter(arr1))
                {
                    a++;
                }
                else if (char.IsNumber(arr1))
                {
                    b++;
                }
                else if (char.IsWhiteSpace(arr1))
                {
                    c++;
                }

            }
            Console.WriteLine("你输入的{0}个英文字母、{1}个数字、{2}个空格", a, b, c);
        }
        static void Text2()
        {
            double[] arr = new double[5];
            double sum = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("请第{0}个评委评分：",(i+1));
                arr[i] = double.Parse(Console.ReadLine());
            }
            foreach (double arr1 in arr)
            {
                sum += arr1;
            }
            double he = sum / 5;
            Console.WriteLine("总成绩" + sum);
            Console.WriteLine("平均成绩" + he);
        }
        static void Text3()
        {
            int[] arr = { 10, 50, 20, 40, 90, 60, 80, 70 };
            Console.WriteLine("排序前");
            foreach (int arr1 in arr)
            {
                Console.Write(arr1 + " ");
            }
            for (int j = 0; j < arr.Length; j++)
            {
                for (int i = 1; i < arr.Length; i++)
                {
                    if (arr[i - 1] < arr[i])
                    {
                        int a = arr[i - 1];
                        arr[i - 1] = arr[i];
                        arr[i] = a;
                    }

                }
            }
            Console.WriteLine();
            Console.WriteLine("排序后");
            foreach (int arr1 in arr)
            {
                Console.Write(arr1 + " ");
            }
            
        }
        static void Text4()
        {
            int[] arr = { 10, 20, 90, 80, 60, 30, 50, 70, 70, 80, 90, 10 };
            foreach (int arr1 in arr)
            {
                Console.Write(arr1 + " ");
            }
            Console.WriteLine();
            Console.WriteLine("请输入要查找的元素");
            int a = int.Parse(Console.ReadLine());
            int b = -1;
            for (int i = 0; i < arr.Length; i++)
            {
                if (a == arr[i])
                {
                    b = i;
                }
            }
            if (b == -1)
            {
                Console.WriteLine("找不到");
            }
            else
            {
                Console.WriteLine("输入值在数组中最后一次出现的位置是{0}", b);
            }
        }
        static void Text5()
        {
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(i + "*" + j + "=" + i * j + " ");
                }
                Console.WriteLine();
            }
        }
        static void Text6()
        {
            Console.WriteLine("请输入空心正方形的边长");
            int a = int.Parse(Console.ReadLine());
            for (int i = 1; i <= a; i++)
            {
                for (int j = 1; j <= a; j++)
                {
                    if (i == 1 || i == a || j == 1 || j == a)
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
        }
        static void Text7()
        {
            Console.WriteLine("请输入菱形的边长");
            int a = int.Parse(Console.ReadLine());
            for (int i = 1; i <= a; i++)
            {
                for (int n = 0; n < a-i; n++)
                {
                    Console.Write(" ");
                }
                for (int j = 0; j < (i * 2 - 1); j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            for (int i = 1; i < a ; i++)
            {
                for (int n = 0; n < i ; n++)
                {
                    Console.Write(" ");
                }
                for (int j = (i * 2 - 1); j <= (a * 2 - 3); j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
        static void Text8()
        {
            Console.WriteLine("请输入实心正方形的边长");
            int a = int.Parse(Console.ReadLine());
            for (int i = 1; i <= a; i++)
            {
                for (int j = 1; j <= a; j++)
                {
                    Console.Write(" *");
                }
                Console.WriteLine();
            }
        }
        static void Text9()
        {
            int[] arr = { 10, 50, 60, 80, 20 };
            foreach (int arr1 in arr)
            {
                Console.Write(arr1 + " ");
            }
            Console.WriteLine();
            for (int i = 0; i < arr.Length; i++)
            {
                if (i%2==0)
                {
                    Console.WriteLine("下标是偶数的元素:{0}",arr[i]);
                }
            }
        }
        static void Text10()
        {
            int[] arr = new int[10];
            arr[0] = 90; arr[1] = 70; arr[2] = 60; arr[3] = 50; arr[4] =40; arr[5] = 30; arr[6] = 20;
            Console.WriteLine("插入前");
            foreach (int arr1 in arr)
            {
                Console.Write(arr1 + " ");
            }
            Console.WriteLine();
            Console.WriteLine("请输入要插入的数");
            int a = int.Parse(Console.ReadLine()); 
            for (int i = 0; i < arr.Length; i++)
            {
                if(arr[i]==0)
                {
                    arr[i] = a;
                    break;
                }
            }
            for (int j = 0; j < arr.Length; j++)
            {
                for (int i = 1; i < arr.Length; i++)
                {
                    if (arr[i - 1] < arr[i])
                    {
                        int b = arr[i - 1];
                        arr[i - 1] = arr[i];
                        arr[i] = b;
                    }

                }
            }
            Console.WriteLine();
            Console.WriteLine("插入后");
            foreach (int arr1 in arr)
            {
                Console.Write(arr1 + " ");
            }
        }
        static void Text11()
        {
            Console.WriteLine("请输入杨辉三角的长度");
            int legth = int.Parse(Console.ReadLine());
            int[][] a = new int[legth][];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = new int[i + 1];
            }
            a[0][0] = 1;
            a[1][0] = 1;
            a[1][1] = 1;
            for (int i = 2; i < a.Length; i++)
            {
                a[i][0] = 1;
                a[i][i] = 1;
                for (int j = 1; j < a[i].Length-1; j++)
                {
                    a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
                }
            }
            for (int i = 0; i < a.Length; i++)
            {
                for (int n = 0; n < legth - i; n++)
                {
                    Console.Write(" ");
                }
                for (int j = 0; j < a[i].Length; j++)
                {
                    Console.Write("{0} ",a[i][j]);
                }
                Console.WriteLine();
            }
        }
    }
}
